from typing import List, Optional


class ListNode:
    def __init__(self, val, next=None):
        self.val = val
        self.next = next

    def __str__(self):
        cur = self
        node = []
        while cur:
            node.append(cur.val)
            cur = cur.next
        return node.__str__()


def node_to_list(head: ListNode) -> List[object]:
    node = []
    while head:
        node.append(head.val)
        head = head.next
    return node


def list_to_node(node: List[object]) -> Optional[ListNode]:
    head = ListNode(-1)
    cur = head
    for n in node:
        cur.next = ListNode(n)
        cur = cur.next
    return head.next
